package com.foryou.wechat.controller;

import com.alibaba.fastjson.JSONObject;
import com.foryou.wechat.model.Query;
import com.foryou.wechat.model.dto.PlaceDTO;
import com.foryou.wechat.service.PlaceService;
import com.foryou.wechat.utils.HttpContextUtils;
import com.foryou.wechat.utils.Response;
import com.foryou.wechat.utils.ValidatorUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by Lee.
 */
@RestController
@RequestMapping("/v/place")
public class PlaceController {

    private final PlaceService placeService;

    public PlaceController(PlaceService placeService) {
        this.placeService = placeService;
    }

    @PostMapping("/addPlace")
    public Response addPlace(@RequestBody PlaceDTO placeDTO) {
        ValidatorUtils.validateEntity(placeDTO);
        return placeService.addPlace(placeDTO);
    }

    @GetMapping("/getPlaceDetail")
    public Response getPlaceDetail(@RequestParam Long placeId) {
        return placeService.getPlaceDetail(placeId);
    }

    @PostMapping("/getForPlaceDetail/{id}")
    public JSONObject getForPlaceDetail(@PathVariable("id") Long placeId) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", placeService.getPlaceDetail(placeId).getData());
        return jsonObject;
    }

    @GetMapping("/collectPlace")
    public Response collectPlace(Long placeId) {
        return placeService.collectPlace(placeId);
    }

    @GetMapping("/cancelPlace")
    public Response cancelPlace(Long placeId) {
        return placeService.cancelPlace(placeId);
    }

    @GetMapping("/clockPlace")
    public Response clockPlace(Long placeId) {
        return placeService.clockPlace(placeId);
    }

    @GetMapping("/commentPlace")
    public Response commentPlace(Long placeId,String content) {
        return placeService.commentPlace(placeId,content);
    }

    @PostMapping("/getPlaceList")
    public Response getPlaceList(@RequestBody Query query) {
        return placeService.getPlaceList(query);
    }

    @GetMapping("/getCollectPlaceList")
    public Response getCollectPlaceList(@RequestParam(defaultValue = "0") int start) {
        return placeService.queryCollectPlaceList(start, HttpContextUtils.getUserId());
    }
}
